package com.bawei.week3;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;

import com.bawei.week3.service.LogServvice;

import java.util.Timer;
import java.util.TimerTask;

public class Main2Activity extends AppCompatActivity {
    private LogServvice.MyBinder myBinder;
    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            myBinder = (LogServvice.MyBinder) service;
            timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    myBinder.dayin();

                }
            },0,5000);
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    private Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        Intent intent = new Intent(this, LogServvice.class);
        bindService(intent,serviceConnection,BIND_AUTO_CREATE);



    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbindService(serviceConnection);
    }
}
